package com.katze.ssh;

import java.io.Serializable;
import java.time.Duration;


public class SshSessionKey implements SecureShellSession, Serializable {
    private String id;
    private String username;
    private String password;
    private String host;
    private Integer port;
    private Duration timeout = Duration.ofSeconds(-1);

    public String getId() {
        if (id == null || id.isBlank()) {
            id = String.format("%s@%s:%d", getUsername(), getHost(), getPort());
        }
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }

    public String getUsername() {
        return username;
    }

    public void setUsername(String username) {
        this.username = username;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    public String getHost() {
        return host;
    }

    public void setHost(String host) {
        this.host = host;
    }

    public int getPort() {
        return port == null? 22:port;
    }

    public void setPort(Integer port) {
        this.port = port;
    }

    public Duration getTimeout() {
        return timeout.isNegative()? Duration.ofSeconds(5):timeout;
    }

    public void setTimeout(Duration timeout) {
        this.timeout = timeout;
    }

    @Override
    public String toString() {
        return "SshSessionProperties{" +
                "id='" + id + '\'' +
                ", username='" + username + '\'' +
                ", password='" + password + '\'' +
                ", host='" + host + '\'' +
                ", port=" + port +
                ", timeout=" + timeout +
                '}';
    }
}
